package com.example.Servlet;

import com.example.Pojo.Member;
import com.example.dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class Invest extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        String inMoney = req.getParameter("investCard");        //充值金额
        String tellphone = req.getParameter("tellphone");       //充值人
        Member member = new UserDaoImpl().getMember(tellphone);     //得到充值人信息
        if (member!=null){
            double in = Double.valueOf(inMoney);
            double getin = Double.valueOf(member.getInvest());
            inMoney = String.valueOf(in + getin);     //将充值金额加入充值人总金额中
            if (new UserDaoImpl().updateCard(inMoney,tellphone) > 0){
                System.out.println("充值成功!");
                writer.print("充值成功!");
            }else {
                System.out.println("充值失败~");
                writer.print("充值失败~");
            }
        }else {
            System.out.println("没有该客户...");
            writer.print("没有该客户...");

        }
    }

}
